package com.hwz.common.validator.MyValidator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class EnumConstraintValidator implements ConstraintValidator<EnumValidate, Integer> {
    private Set<Integer> set = new HashSet<>();
    private String regexp;
    @Override
    public void initialize(EnumValidate constraintAnnotation) {
        for (Integer i : constraintAnnotation.values()) {
            set.add(i);
        }
//        this.regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(value);

//        return value.toString().matches(regexp);
    }
}
